package com.ykdl.member.kid.adapters;

import java.util.List;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.core.BitmapSize;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.CouponFragmentAdapter.ViewHolder;
import com.ykdl.member.kid.adapters.base.BaseObjectListAdapter;
import com.ykdl.member.kid.beans.ProductBean;
import com.ykdl.member.kid.beans.TicketBean;

import android.content.Context;
import android.util.Config;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/********************************************************************************

** 作者： jiafeiyu
** 创始时间：2015-4-27
** 描述：
**    门店货架--之门店adapter

*********************************************************************************/
public class StoreFragmentAdapter extends BaseAdapter {
	private List<ProductBean>  data_list;
	private BitmapUtils bitmapUtil;
	private Context mContext ;
	private LayoutInflater inflater;
	public StoreFragmentAdapter(Context context) {
		mContext = context;
		bitmapUtil = new BitmapUtils(context);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defult_head_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_head_icon);
		inflater = LayoutInflater.from(context);
	}
	public void setData(List<ProductBean>  data_list){
		this.data_list = data_list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (data_list!=null&&data_list.size()>0) {
			return data_list.size();
		}else {
			return 0;
		}
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView==null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_store_fragment_adapter, null);
			holder.tv_item_store_old_price_lp =(ImageView) convertView.findViewById(R.id.tv_item_store_old_price_lp);
			holder.iv_item_store_image =(ImageView) convertView.findViewById(R.id.iv_item_store_image);
			holder.tv_item_store_old_price =(TextView) convertView.findViewById(R.id.tv_item_store_old_price);
			holder.tv_item_store_price =(TextView) convertView.findViewById(R.id.tv_item_store_price);
			holder.tv_item_store_description =(TextView) convertView.findViewById(R.id.tv_item_store_description);
			holder.tv_item_store_chuxiao =(TextView) convertView.findViewById(R.id.tv_item_store_chuxiao);
			holder.tv_store_online_pay = (TextView) convertView.findViewById(R.id.tv_store_online_pay);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		initView(holder,position);
		return convertView;
	}
	private void initView(ViewHolder holder, final int position) {
		ProductBean bean = data_list.get(position);
		String url ="";
		if (null!=bean.getList_pic()) {
			url=bean.getList_pic().getFile_url();
		}
		bitmapUtil.configDefaultBitmapMaxSize(holder.iv_item_store_image.getWidth(), holder.iv_item_store_image.getHeight());
		bitmapUtil.display(holder.iv_item_store_image, url);
		if (bean.getProduct_type()==1) {
			holder.tv_store_online_pay.setVisibility(View.GONE);
		}else {
			holder.tv_store_online_pay.setVisibility(View.VISIBLE);
		}
		if (bean.isIs_debate()) {
			holder.tv_item_store_chuxiao.setText("降价");
			holder.tv_item_store_old_price.setVisibility(View.VISIBLE);
			holder.tv_item_store_old_price_lp.setVisibility(View.VISIBLE);
			holder.tv_item_store_chuxiao.setVisibility(View.VISIBLE);
			
			holder.tv_item_store_price.setText(bean.getDebate().getDebate_price());
			holder.tv_item_store_old_price.setText(bean.getPrice());
		}else {
			holder.tv_item_store_chuxiao.setVisibility(View.GONE);
			holder.tv_item_store_price.setText(bean.getPrice());
			holder.tv_item_store_old_price.setVisibility(View.GONE);
			holder.tv_item_store_old_price_lp.setVisibility(View.GONE);
		}
		holder.tv_item_store_description.setText(bean.getName());
		
	}
	
	static class ViewHolder{
		ImageView iv_item_store_image,tv_item_store_old_price_lp;
		TextView tv_item_store_old_price;
		TextView tv_item_store_price;
		TextView tv_item_store_description;
		TextView tv_item_store_chuxiao;
		TextView tv_store_online_pay;
	}


	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data_list.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
}
